package guoanmaker.operator.business.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import guoanmaker.operator.business.model.OperatorUser;


/**
*
* 
* @author vladimir.stankovic
*
* Aug 16, 2016
*/
public interface OperatorUserRepository extends JpaRepository<OperatorUser, String>, JpaSpecificationExecutor<OperatorUser>{
   @Query("select u from OperatorUser u left join fetch u.roles r where u.username=:username")
    public Optional<OperatorUser> findByUsername(@Param("username") String username);
	
    @Query("select u from OperatorUser u where u.username=:username and u.password=:password")	
	public OperatorUser  operatorLogin(@Param("username") String username,@Param("password") String password);
    
    @Query("select u from OperatorUser u  where u.username=:username")
    public List<OperatorUser> findUserByUsername(@Param("username") String username);
    
    @Query("select u from OperatorUser u  where u.id=:id")
    public OperatorUser  selectById(@Param("id") String id);
    
    @Query("select o from OperatorUser o  where o.departmentId=:departmentId")
    public List<OperatorUser>  selectBydepId(@Param("departmentId") String departmentId);
   
    @Query("select o from OperatorUser o  where o.roleId=:roleId")
    public List<OperatorUser>  selectByroleId(@Param("roleId") String roleId);
    
    
    
    @Query("select u from OperatorUser u ORDER BY u.createDate DESC")
    public List<OperatorUser> queryAll();
    
    @Query("select u from OperatorUser u where u.userPhone=:userPhone ")	
   	public List<OperatorUser>  operatorByPhone(@Param("userPhone") String userPhone);
    @Query("select u from OperatorUser u where u.userPhone=:userPhone and u.username=:username")	
    public List<OperatorUser>  operatorByPhoneAndUsername(@Param("userPhone") String userPhone,@Param("username") String username);
    
    @Query("select u from OperatorUser u where u.name like CONCAT('%',:name,'%')")
    public List<OperatorUser> selectByname(@Param("name") String name);
    
}
